Skip to content

Bump to Rector ^2.4.1 and replace deprecated file to getFile() on rector rule#4

Merged
guanguans merged 4 commits intoguanguans:mainfrom
samsonasik:bump-rector-241
Apr 8, 2026
Merged

Bump to Rector ^2.4.1 and replace deprecated file to getFile() on rector rule#4
guanguans merged 4 commits intoguanguans:mainfrom
samsonasik:bump-rector-241

Conversation

@samsonasik
Copy link
Copy Markdown
Contributor

@samsonasik samsonasik commented Apr 8, 2026

Ref

Summary by CodeRabbit

版本更新说明

  • 维护

    • 更新 Rector 依赖版本至 2.4.1,支持最新的代码规范和转换规则
    • 从默认配置中移除了一个特定的代码检查规则
  • 代码重构

    • 优化了异常处理中文件路径的访问机制
    • 改进了文件操作方法中的变量引用逻辑,提升代码质量

@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Upgrade Rector to ^2.4.1 and update deprecated API usage

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Upgrade Rector dependency from ^2.3 to ^2.4.1
• Replace deprecated $this->file property with getFile() method
• Replace Str::of() calls with \str() helper function
• Remove unused SafeDeclareStrictTypesRector rule and import
• Refactor variable naming for improved code clarity
• Remove duplicate PHPUnit DataProvider attribute annotation
Diagram
flowchart LR
  A["Rector ^2.3"] -->|"Upgrade to"| B["Rector ^2.4.1"]
  B -->|"Requires API changes"| C["Replace deprecated APIs"]
  C -->|"file property"| D["Use getFile() method"]
  C -->|"Str::of()"| E["Use str() helper"]
  F["Remove unused rules"] -->|"SafeDeclareStrictTypesRector"| G["Clean config"]
Loading

Grey Divider

File Changes

1. composer.json Dependencies +1/-1

Bump Rector dependency version constraint

composer.json


2. rector.dist.php ⚙️ Configuration changes +0/-2

Remove deprecated SafeDeclareStrictTypesRector rule

rector.dist.php


3. src/Exception/RectorErrorException.php 🐞 Bug fix +1/-3

Replace deprecated file property with getFile()

src/Exception/RectorErrorException.php


View more (7)
4. src/Rector/AbstractRector.php ✨ Enhancement +1/-1

Replace Str::of() with str() helper function

src/Rector/AbstractRector.php


5. src/Rector/Array_/UpdateRectorCodeSamplesFromFixturesRector.php ✨ Enhancement +3/-3

Replace Str::of() with str() helper function

src/Rector/Array_/UpdateRectorCodeSamplesFromFixturesRector.php


6. src/Rector/File/AddNoinspectionDocblockToFileFirstStmtRector.php 🐞 Bug fix +3/-3

Replace deprecated file property with getFile()

src/Rector/File/AddNoinspectionDocblockToFileFirstStmtRector.php


7. src/Rector/File/SortFileFunctionStmtRector.php Miscellaneous +8/-8

Refactor variable naming for improved clarity

src/Rector/File/SortFileFunctionStmtRector.php


8. src/Support/ComposerScripts.php ✨ Enhancement +3/-3

Replace Str::of() with str() helper function

src/Support/ComposerScripts.php


9. tests/Rector/AbstractRectorTestCase.php 🧪 Tests +3/-4

Replace Str::of() and remove duplicate DataProvider attribute

tests/Rector/AbstractRectorTestCase.php


10. tests/Support/HelpersTest.php 🧪 Tests +2/-2

Replace Str::of() with str() helper function

tests/Support/HelpersTest.php


Grey Divider

Qodo Logo

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19a5dc69-6e9e-4886-9f7d-256b4df636c9

📥 Commits

Reviewing files that changed from the base of the PR and between 4a11f63 and ddee9f8.

📒 Files selected for processing (1)
  • src/Exception/RectorErrorException.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Exception/RectorErrorException.php

Walkthrough

升级Rector依赖版本从^2.3至^2.4.1。移除SafeDeclareStrictTypesRector规则。重构多个类中的文件访问方式,将属性直接访问替换为方法调用。调整SortFileFunctionStmtRector中的节点变量处理逻辑。

Changes

Cohort / File(s) Summary
依赖版本升级
composer.json
rector/rector依赖约束从^2.3更新至^2.4.1
配置调整
rector.dist.php
移除了SafeDeclareStrictTypesRector的导入和规则注册。
文件访问方式重构
src/Exception/RectorErrorException.php, src/Rector/File/AddNoinspectionDocblockToFileFirstStmtRector.php
将直接属性访问$this->file->getFilePath()改为方法调用$this->getFile()->getFilePath(),移除关联的PHPDoc属性声明。
节点处理逻辑优化
src/Rector/File/SortFileFunctionStmtRector.php
refactor()方法中的$rootNode变量替换为$stmt,更新所有后续逻辑以使用新的局部变量。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 版本升级跳跃欢,
规则精简更轻盈,
属性改访问器方法,
节点变量换新颜,
Rector舞蹈步步妙!✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地总结了此拉取请求的主要变更:更新Rector版本至^2.4.1并将deprecated的file属性替换为getFile()方法。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review bot commented Apr 8, 2026

Code Review by Qodo

🐞 Bugs (1)   📘 Rule violations (0)   📎 Requirement gaps (0)   🎨 UX Issues (0)
🐞\ ⚙ Maintainability (1)

Grey Divider


Remediation recommended

1. Unused Str imports 🐞
Description
After switching from Str::of(...) to \str(...), multiple files still import Illuminate\Support\Str
but never use it, which can cause coding-standard/static-analysis failures and adds misleading
dependencies.
Code

src/Rector/AbstractRector.php[44]

+        return (string) \str(static::class)
Evidence
AbstractRector now uses \str(static::class) for Stringable operations, but still imports
Illuminate\Support\Str. The same pattern exists in RectorErrorException and
UpdateRectorCodeSamplesFromFixturesRector: Str is imported, yet the updated code uses \str(...) and
contains no Str::... usages.

src/Rector/AbstractRector.php[15-50]
src/Exception/RectorErrorException.php[14-47]
src/Rector/Array_/UpdateRectorCodeSamplesFromFixturesRector.php[17-41]
src/Rector/Array_/UpdateRectorCodeSamplesFromFixturesRector.php[272-309]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
After replacing `Str::of(...)` with the global `\str(...)` helper, some files still have `use Illuminate\Support\Str;` even though they no longer reference `Str`. This can fail style/static-analysis checks and makes the code misleading.

### Issue Context
The refactor changed fluent string calls to use `\str(...)`, but did not remove now-unused imports.

### Fix Focus Areas
- src/Rector/AbstractRector.php[15-20]
- src/Exception/RectorErrorException.php[16-21]
- src/Rector/Array_/UpdateRectorCodeSamplesFromFixturesRector.php[19-23]

### Expected change
Remove the unused `use Illuminate\Support\Str;` lines (leave any other `Str` imports where `Str::...` is still used).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@samsonasik
Copy link
Copy Markdown
Contributor Author

samsonasik commented Apr 8, 2026

@guanguans ready for merge for immediate new release 👍 , I tried only apply related changes as possible ;)

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Exception/RectorErrorException.php (1)

36-42: ⚠️ Potential issue | 🟡 Minor

bindTo 方式访问 getFile() 方法是必要的权衡方案。

由于 RectorErrorException 继承 Error 而非 AbstractRector,无法直接访问受保护的 getFile() 方法。使用 bindTo($rector, $rector) 将闭包临时绑定到 Rector 实例的作用域是解决这个问题的合理方式。

虽然 @phpstan-ignore method.nonObject 注释表明静态分析器无法理解 bindTo 的行为,但这不影响运行时的正确性——getFile() 是 Rector 核心 API,不会轻易变更。若有其他需要减少代码复杂性,可考虑在构造函数中传入文件路径作为参数,但现有实现是务实的权衡。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Exception/RectorErrorException.php` around lines 36 - 42, The use of a
bound closure to call the protected getFile() from RectorErrorException is
acceptable: keep the (fn (): string =>
$this->getFile()->getFilePath())->bindTo($rector, $rector)() pattern and retain
the `@phpstan-ignore` method.nonObject, but add a short inline comment near that
expression explaining why bindTo is used (RectorErrorException extends Error so
it cannot access protected getFile() directly) and mention that constructor
injection of the file path is an alternative; ensure symbols referenced are
RectorErrorException, getFile(), and bindTo in your comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/Exception/RectorErrorException.php`:
- Around line 36-42: The use of a bound closure to call the protected getFile()
from RectorErrorException is acceptable: keep the (fn (): string =>
$this->getFile()->getFilePath())->bindTo($rector, $rector)() pattern and retain
the `@phpstan-ignore` method.nonObject, but add a short inline comment near that
expression explaining why bindTo is used (RectorErrorException extends Error so
it cannot access protected getFile() directly) and mention that constructor
injection of the file path is an alternative; ensure symbols referenced are
RectorErrorException, getFile(), and bindTo in your comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e886fcf-82b3-4873-aefc-3e6474b634c1

📥 Commits

Reviewing files that changed from the base of the PR and between 57f87e8 and 4a11f63.

📒 Files selected for processing (10)
  • composer.json
  • rector.dist.php
  • src/Exception/RectorErrorException.php
  • src/Rector/AbstractRector.php
  • src/Rector/Array_/UpdateRectorCodeSamplesFromFixturesRector.php
  • src/Rector/File/AddNoinspectionDocblockToFileFirstStmtRector.php
  • src/Rector/File/SortFileFunctionStmtRector.php
  • src/Support/ComposerScripts.php
  • tests/Rector/AbstractRectorTestCase.php
  • tests/Support/HelpersTest.php
💤 Files with no reviewable changes (1)
  • rector.dist.php

@guanguans
Copy link
Copy Markdown
Owner

@samsonasik Thanks.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.90%. Comparing base (57f87e8) to head (ddee9f8).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main       #4   +/-   ##
=========================================
  Coverage     99.90%   99.90%           
  Complexity      308      308           
=========================================
  Files            20       20           
  Lines          1011     1011           
=========================================
  Hits           1010     1010           
  Misses            1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@guanguans guanguans merged commit c7cd1a0 into guanguans:main Apr 8, 2026
12 checks passed
@samsonasik samsonasik deleted the bump-rector-241 branch April 9, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants